package com.app.micaihu.view.main.game;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.app.micaihu.R;
import com.app.micaihu.app.AppApplication;
import com.app.micaihu.base.BaseOldActivity;
import com.app.micaihu.base.bean.DataBean;
import com.app.micaihu.bean.comment.NewsComment;
import com.app.micaihu.bean.game.GameContent;
import com.app.micaihu.bean.game.GameScoreBean;
import com.app.micaihu.bean.news.ShareBean;
import com.app.micaihu.configure.Config;
import com.app.micaihu.configure.TypeConstant;
import com.app.micaihu.configure.URIContant;
import com.app.micaihu.configure.UmEventId;
import com.app.micaihu.configure.UserConfigTools;
import com.app.micaihu.custom.components.downandupload.LoadingView;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.widget.LoadView;
import com.app.micaihu.custom.view.RatingBarView;
import com.app.micaihu.listener.HttpListener;
import com.app.micaihu.manager.UserInforManager;
import com.app.micaihu.utils.AppShareUtils;
import com.app.micaihu.utils.DialogUtils;
import com.app.micaihu.videoplayer.JCMediaManager;
import com.app.micaihu.videoplayer.JCVideoPlayer;
import com.app.micaihu.videoplayer.JCVideoPlayerManager;
import com.app.micaihu.view.main.MainActivity;
import com.app.micaihu.view.main.game.view.GameCommentListView;
import com.app.micaihu.view.main.game.view.GameDescView;
import com.app.micaihu.view.newsdetail.ImageShowActivity;
import com.app.micaihu.view.newsdetail.VideoDetailActivity;
import com.app.micaihu.view.newsdetail.view.DetailScrollView;
import com.app.utils.util.StringUtils;
import com.app.utils.util.ToastUtils;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;
import com.blankj.utilcode.util.ActivityUtils;
import com.google.gson.reflect.TypeToken;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import com.umeng.socialize.UMShareAPI;

import java.util.ArrayList;
import java.util.HashMap;

import de.greenrobot.event.EventBus;

/**
 * Created by Guo on 2017/2/9.
 * <p>
 * <p>
 * 游戏视频/下载内页
 */

public class GameDetailActivity extends BaseOldActivity implements View.OnClickListener, DialogUtils.OnDialogBtnClickListener, GameDescView.OnViewScrollListener, DetailScrollView.OnScrollListener {

    /************
     * 页面控件 start
     ****************/
    private GameCommentListView mCommentListview;//评论listview
    private LoadView mNewsLoadView;//文章加载提示
    /**************
     * 页面数据 start
     ************/
    private String newsId;//视频文章id
    private String pageSourceType;//来源类型 1正常列表 2相关列表 3网页 4push
    private String serialId;//后台该文章的位置id
    private GameContent mGameContent;//视频详情数据

    /********
     * 页面工具
     ************/


    private boolean onPageFinish;//是否加载成功

    private TextView tvShare, tvComment;
    private DetailScrollView detailScrollView;
    private GameDescView mGameContentView;
    private LinearLayout stickyContainer;
    private LoadingView btnGoto;
    private TextView btnComment;
    private LinearLayout btnCommentContaner;
    private RatingBarView rbvStar;
    private ImageView backView;
    private View driver;
    private ImageView moreView;
    private View titlelayout;
    private CustomImageView civAppIcon;
    private TextView tvAppTitle;
    private TranslateAnimation enterAnimation;
    private TranslateAnimation outAnimation;
    private LinearLayout infoTitle;
    private boolean isTinyWindowPlayer;
    //    private boolean isShowTitle;
    private AppShareUtils mShareUtils;
    LoadingView gameLoading;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getIntentData();
        colorId = R.color.common_bg_color_8;
        super.onCreate(savedInstanceState);
        addContentView(R.layout.activity_game_detail);
        //改变通知栏顶部
        pageConfigNotify = true;
        EventBus.getDefault().register(this);
        //初始化页面控件
        initView();
        //释放掉JC
        JCVideoPlayer.releaseAllVideos();
        //加载页面数据
        loadData();
    }

    /************** 页面初始化 start *******************/


    public DetailScrollView getDetailScrollView() {
        return detailScrollView;
    }

    /**
     * 初始化页面控件
     */
    private void initView() {
        gameLoading = findViewById(R.id.gameLoading);
        tvShare = findViewById(R.id.tvShare);
        tvComment = findViewById(R.id.tvComment);
        tvShare.setOnClickListener(this);
        tvComment.setOnClickListener(this);
        detailScrollView = (DetailScrollView) findViewById(R.id.psv_psrsolview);
        mGameContentView = (GameDescView) findViewById(R.id.gdv_game_content);
        mGameContentView.initView();
        mGameContentView.setActivity(this);
        this.mGameContentView.getCwvContentWebview().setFocusable(false);
        mCommentListview = (GameCommentListView) findViewById(R.id.prlv_listview);
        mNewsLoadView = (LoadView) findViewById(R.id.lv_laodview);


        //sticky布局
        stickyContainer = (LinearLayout) findViewById(R.id.ll_btn_container_gone);
        btnGoto = (LoadingView) findViewById(R.id.btn_opration_gone);
        btnGoto.setEventData(UmEventId.INSTANCE.getGamedetail());
        btnComment = (TextView) findViewById(R.id.tv_gocomment_gone);
        btnCommentContaner = (LinearLayout) findViewById(R.id.btn_comment_gone);
        rbvStar = (RatingBarView) findViewById(R.id.rb_comment_scroe_gone);

//        btnGoto.setOnClickListener(mGameContentView);
        btnCommentContaner.setOnClickListener(mGameContentView);

//        btnGoto.setText(AppApplication.getInstance().getString(R.string.game_down));
        btnComment.setText(AppApplication.getInstance().getString(R.string.game_go_comment));

        //线
        driver = findViewById(R.id.game_divider);
        driver.setVisibility(View.GONE);

        //后退按钮
        backView = (ImageView) findViewById(R.id.game_left);
        backView.setImageResource(R.drawable.common_backbtn_icon);

        //右侧更多
        moreView = (ImageView) findViewById(R.id.game_right);
        moreView.setImageResource(R.drawable.detail_menu_white_selector);
        moreView.setOnClickListener(this);

        //背景
        titlelayout = findViewById(R.id.game_bg);
        titlelayout.setBackgroundColor(getResources().getColor(R.color.transparent));


        //info
        civAppIcon = (CustomImageView) findViewById(R.id.page_head_usericon);
        tvAppTitle = (TextView) findViewById(R.id.page_head_author);
        infoTitle = (LinearLayout) findViewById(R.id.page_head_author_layout);
        mNewsLoadView.setErrorPageClickListener(this);
        configContentWebView();
        findViewById(R.id.ll_head_click).setOnClickListener(this);


        detailScrollView.setOnScrollListener(this);

    }

    /**
     * 获取传输的页面数据
     */
    private void getIntentData() {
        Intent intent = getIntent();
        if (intent == null) {
            return;
        }
        newsId = intent.getStringExtra(Config.Extra.PARAMETER1);
        pageSourceType = intent.getStringExtra(Config.Extra.PARAMETER2);
        serialId = intent.getStringExtra("serialId");
    }

    /**
     * 加载数据
     */
    private void loadData() {

        HashMap<String, String> parmsMap = new HashMap<String, String>();

        parmsMap.put("articleId", newsId + "");
        parmsMap.put("sourceType", pageSourceType + "");
        if (UserInforManager.getInstance().isLogin()) {
            parmsMap.put("uid", UserInforManager.getInstance().getUserInfor().getUid());
        }
        HttpListener<DataBean<GameContent>> httpListener = new HttpListener<DataBean<GameContent>>() {

            @Override
            public void onStart() {
                if (mNewsLoadView != null) {
                    mNewsLoadView.showLoadPage(null);
                }
            }

            @Override
            public void onError(VolleyError error) {
                if (mNewsLoadView != null) {
                    mNewsLoadView.showErrorPage(AppApplication.getInstance().getString(R.string.neterror_click));
                } else {
                    ToastUtils.showText("服务器连接失败,请稍候再试");
                }
            }

            @Override
            public void onSuccess(DataBean<GameContent> response) {
                if (response.noErrorData()) {
//                    mGameContentView.scrollTop();
                    mGameContent = response.getData();

                    //适配数据
                    adapterUI();
                    //加载评论
                    if (mGameContent != null) {
                        loadCommentData(mGameContent);
                    }

                } else {
                    mNewsLoadView.showErrorPage(response.getNnderstoodMsg());
                }
            }
        };
        //请求网络
        addPostRequest(URIContant.GAME_VIDEO_DETAIL, new TypeToken<DataBean<GameContent>>() {
        }.getType(), parmsMap, httpListener);


    }


    /**
     * 加载评论数据
     *
     * @param mGameContent
     */
    private void loadCommentData(GameContent mGameContent) {
        if (mGameContent != null) {
            //适配评论
            mCommentListview.setEmptyViewOnClickListener(this);
            //加载评论
            mCommentListview.startLoadData(this, mGameContent.getArticleId(), mPageName);
            //加载相关新闻模块
//            detailNewsView.setAboutData(mNewsContent.getAboutList(), mNewsContent.getAdList(), mNewsContent.getTopAdInfo(), NewsDetailActivity.this);
        } else {
            //禁止滑动到第二个view
            detailScrollView.setScrollSecondView(true);
        }
    }

    /**
     * 适配数据
     */
    private void adapterUI() {
        if (mGameContent == null) {
            mNewsLoadView.showErrorPage(DataBean.getErrorMsg());
            return;
        }
        gameLoading.setTag(mGameContent);
        gameLoading.setTag(R.id.tag_four, "游戏详情");
        playVideo();
        //设置透明标题和 隐藏loadview
        setTitleShow(false);
        LoadImageUtils.getInstance().loadCircleImage(civAppIcon, mGameContent.getAppIcon());
        tvAppTitle.setText(mGameContent.getArticleTitle());


        //隐藏等待提示
        mNewsLoadView.showSuccess();


        //设置游戏介绍的数据
        setDataForContent();
    }


    /**
     * 改变标题
     *
     * @param sloid
     */
    private void changeTitle(boolean sloid) {
        if (sloid) {
            if (infoTitle.getVisibility() == View.VISIBLE) {
                return;
            }
            driver.setVisibility(View.VISIBLE);
            //后退按钮
            backView.setImageResource(R.drawable.common_back_selector);
            //右侧更多
            moreView.setImageResource(R.drawable.detail_menu_black_selector);
            //背景
            titlelayout.setBackgroundColor(getResources().getColor(R.color.common_bg_color_2));
            if (infoTitle.getVisibility() == View.GONE) {
                if (enterAnimation == null) {
                    enterAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
                            -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
                    enterAnimation.setDuration(300);
                    enterAnimation.setFillAfter(true);
                }
                infoTitle.startAnimation(enterAnimation);
                infoTitle.setVisibility(View.VISIBLE);
            }
        } else {
            if (infoTitle.getVisibility() == View.GONE) {
                return;
            }
            //线
            driver.setVisibility(View.GONE);
            //后退按钮
            backView.setImageResource(R.drawable.common_backbtn_icon);
            //右侧更多
            moreView.setImageResource(R.drawable.detail_menu_white_selector);
            //背景
            titlelayout.setBackgroundColor(getResources().getColor(R.color.transparent));
            //动画
            if (infoTitle.getVisibility() == View.VISIBLE) {
                if (outAnimation == null) {
                    outAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
                            0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
                            -1.0f);
                    outAnimation.setDuration(300);
                    outAnimation.setFillAfter(true);
                }
                infoTitle.startAnimation(outAnimation);
                infoTitle.setVisibility(View.GONE);
            }

        }
    }


//    int tt;

    /**
     * 设置webview 的  内容数据
     */
    private void setDataForContent() {
        this.mGameContentView.getCwvContentWebview().addJavascriptInterface(new JavascriptInterface(mActivity), "imagelistner");
        btnGoto.setTag(mGameContent);
        btnGoto.setTag(R.id.tag_four, "游戏详情");


        //加载新闻内容
        mGameContentView.setGameContentData(mGameContent);
        this.mGameContentView.setOnViewScrollListener(this);
        //加载相关攻略
        mGameContentView.setAboutStretegyData(mGameContent.getStrategyList());
        mGameContentView.setAboutGameList(mGameContent.getRelatedGame());
        //设置炫富的星星
        if (rbvStar != null) {
            rbvStar.setStar(StringUtils.toFloat(mGameContent.getLatestStar(), 0.0f));
        }

    }


    /**
     * 控制 滑动时候显示/隐藏title
     *
     * @param t
     */
    public void showOrHideSticky(int t, int top) {
        if (mGameContentView != null && mGameContent != null) {
            if (t > top) {//显示悬挂
//                if (stickyContainer.getVisibility() == View.GONE) {
//                    stickyContainer.setVisibility(View.VISIBLE);
//                }
                changeTitle(true);
            } else {//隐藏悬挂
//                if (stickyContainer.getVisibility() == View.VISIBLE) {
//                    stickyContainer.setVisibility(View.GONE);
//                }
                changeTitle(false);
            }


            if (Build.VERSION.SDK_INT != Build.VERSION_CODES.JELLY_BEAN_MR1) {
                //小窗视频
                if (mGameContentView.getJcVideoplayer() != null && mGameContentView.getJcVideoplayer().isPlaying()
                        && mGameContentView.getJcVideoplayer().currentState != JCVideoPlayer.CURRENT_STATE_PAUSE) {
                    if (t > mGameContentView.getVideoTinyTop() && !isTinyWindowPlayer) {
                        mGameContentView.getJcVideoplayer().startWindowTiny(null);
                        isTinyWindowPlayer = true;
                    } else if (t < mGameContentView.getVideoTinyTop() && isTinyWindowPlayer) {
                        new Handler().post(new Runnable() {
                            public void run() {
                                mGameContentView.getJcVideoplayer().backPress();
                                isTinyWindowPlayer = false;
                            }
                        });

                    }
                }
            }

        }


    }

    /**
     * 配置内容的webView
     */
    @SuppressLint("SetJavaScriptEnabled")
    private void configContentWebView() {
        if (mGameContentView != null && mGameContentView.getCwvContentWebview() != null && !mGameContentView.getCwvContentWebview().getIsDestory()) {
            mGameContentView.getCwvContentWebview().setWebViewClient(new MyWebViewClient());
        }

    }

    @Override
    public void onScrollChanged(int l, int t, int oldl, int oldt) {

        if (mGameContentView != null && mGameContentView.getContent() != null) {
            if (mGameContentView.getContent().getVisibility() == View.GONE) {
                int i = mGameContentView.getStickyTop() - ViewSizeUtils.dp2px(this, 44);
                showOrHideSticky(t, (mGameContentView.getStickyTop() - ViewSizeUtils.dp2px(this, 44)));
            }

        }

    }

    @Override
    public void onViewScrolling(int l, int t, int oldl, int oldt) {
        if (mGameContentView != null && mGameContentView.getContent() != null) {
            if (mGameContentView.getContent().getVisibility() != View.GONE) {
                showOrHideSticky(t, (mGameContentView.getStickyTop() - ViewSizeUtils.dp2px(this, 44)));
            }

        }
    }


    // js通信接口
    public class JavascriptInterface {

        private Context context;

        public JavascriptInterface(Context context) {
            this.context = context;
        }

        @android.webkit.JavascriptInterface
        public void openImage(String img, String index) {
            Intent intent = new Intent();
            String[] imgs = img.split(",");
            ArrayList<String> imgsUrl = new ArrayList<String>();
            for (String s : imgs) {
                imgsUrl.add(s);
            }
            intent.putStringArrayListExtra(Config.Extra.PARAMETER1, imgsUrl);
            intent.putExtra(Config.Extra.PARAMETER2, Integer.valueOf(index));
            if (mGameContent != null) {
                intent.putExtra("title", mGameContent.getArticleTitle());
            }
            intent.setClass(context, ImageShowActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            overridePendingTransition(R.anim.base_alpha_in, R.anim.base_slide_remain);// 前一个参数是下一个Activity的效果
        }
    }

    // 监听
    private class MyWebViewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (TextUtils.isEmpty(url) || url.length() < 5) {
                return false;
            }
            //判断是否为http协议，如果是自定义协议则交给系统
            String httpStr = "";
            try {
                httpStr = url.substring(0, 4);
            } catch (Exception e1) {
                e1.printStackTrace();
                return false;
            }
            if (!TextUtils.isEmpty(httpStr) && !httpStr.equals("http")
                    && !httpStr.equals("https")) {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse(url);
                intent.setData(content_url);
                try {
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return true;
            } else {
                view.loadUrl(url);
                return true;
            }
        }


        @Override
        public void onPageFinished(WebView view, String url) {
            //因为 webview的onPageFinished 会执行两次
            // 所以这里逻辑处理一下 只执行一次
            if (!onPageFinish && !GameDetailActivity.this.isFinishing()) {
                onPageFinish = true;

                //添加JS函数
                addImageClickListner();
                if (mCommentListview != null) {
                    mCommentListview.setVisibility(View.VISIBLE);
                }
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode,
                                    String description, String failingUrl) {
            // progressBar.setVisibility(View.GONE);
//            view.goBack();
            super.onReceivedError(view, errorCode, description, failingUrl);
        }

    }


    // 注入js函数监听
    private void addImageClickListner() {
        if (mGameContentView.getCwvContentWebview() == null) return;
        // 这段js函数的功能就是，遍历所有的img几点，并添加onclick函数，在还是执行的时候调用本地接口传递url过去
        mGameContentView.getCwvContentWebview().loadUrl("javascript:(function(){"
                + "var objs = document.getElementsByTagName(\"img\");"
                + "var imgurl=''; " + "for(var i=0;i<objs.length;i++)  " + "{"
                + "imgurl+=objs[i].getAttribute('data-original')+',';"
                + "objs[i].setAttribute('myid',''+i);"
                + "objs[i].onclick=function()  " + "    {  "
                + "var myid=this.getAttribute('myid');"
                + "  window.imagelistner.openImage(imgurl,myid);  " + "    }  "
                + "}" + "})()");
    }

    /**
     * 播放云视频
     */
    private void playVideo() {
        if (mGameContentView == null || mGameContentView.getJcVideoplayer() == null || mGameContent == null) {
            return;
        }
        ShareBean shareBean = new ShareBean();
        shareBean.setArticleId(mGameContent.getArticleId());
        mGameContentView.getJcVideoplayer().setShareBean(shareBean);
        if (UserConfigTools.isAutoPaly) {
            if (CURRENT_STATE <= JCVideoPlayer.CURRENT_STATE_NORMAL) {
                //直接播放接口的Url
                mGameContentView.getJcVideoplayer().setUp(mGameContent.getVideoCurl(), JCVideoPlayer.SCREEN_LAYOUT_NORMAL,
                        mGameContent.getArticleTitle(), mGameContent.getPlotImg());
                mGameContentView.getJcVideoplayer().startPlay();
            } else {
                //接着外面的视频播放
                mGameContentView.getJcVideoplayer().setVisibility(View.VISIBLE);
                mGameContentView.getJcVideoplayer().setUp(URL, JCVideoPlayer.SCREEN_LAYOUT_NORMAL, OBJECTS);
                mGameContentView.getJcVideoplayer().setUiWitStateAndScreen(CURRENT_STATE);
                mGameContentView.getJcVideoplayer().addTextureView();
                JCVideoPlayerManager.setFirstFloor(mGameContentView.getJcVideoplayer());
                //继续播放
                try {
                    JCMediaManager.instance().mediaPlayer.start();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                }
            }
        } else {
            //直接播放接口的Url
            mGameContentView.getJcVideoplayer().setUp(mGameContent.getVideoCurl(), JCVideoPlayer.SCREEN_LAYOUT_NORMAL,
                    mGameContent.getArticleTitle(), mGameContent.getPlotImg());
        }


    }


    /**
     * 更改UI的 操作
     *
     * @param newsComment p评论后更改UI
     */
    public void onEventMainThread(NewsComment newsComment) {
        if (newsComment != null) {
            if (mCommentListview != null) {
                mCommentListview.addComment(newsComment);

            }


            if (mGameContent != null) {
                mGameContent.setLatestStar(newsComment.getStar());
            }
            flushScore();


        }


    }


    /**
     * 刷新 分数
     */
    private void flushScore() {
        if (mGameContent == null) return;
        HashMap<String, String> params = new HashMap<>();
        params.put("articleId", mGameContent.getArticleId());
        HttpListener<DataBean<GameScoreBean>> httpListener = new HttpListener<DataBean<GameScoreBean>>() {
            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onError(VolleyError error) {
            }

            @Override
            public void onSuccess(DataBean<GameScoreBean> response) {
                if (response.noErrorData()) {

                    GameScoreBean gameScoreBean = response.getData();
                    String gradeScore = gameScoreBean.getGradeScore();
                    String perStartNum = gameScoreBean.getPerStartNum();
                    mGameContent.setGradeScore(gradeScore);
                    mGameContent.setPerStartNum(perStartNum);

                    if (mGameContentView != null) {
                        mGameContentView.flushScore();
                    }
                    if (rbvStar != null) {
                        rbvStar.setStar(StringUtils.toFloat(mGameContent.getLatestStar(), 0.0f));
                    }
                }
            }
        };

        addPostCacheRequest(URIContant.GAME_GRADE_SCALE, new TypeToken<DataBean<GameScoreBean>>() {
        }.getType(), params, httpListener);


    }


    /**************
     * 页面初始化 end
     *******************/

    @Override
    public void onClick(View v) {
        if (v == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.tvShare:
            case R.id.game_right://分享的按钮
                share();
                break;
            case R.id.error_page://重新加载页面数据
                loadData();
                break;
            case R.id.tvComment://重新加载页面数据
                if (mGameContent != null) {
                    Intent intent = new Intent(this, GameCommentActivity.class);
                    intent.putExtra(Config.Extra.PARAMETER1, mGameContent.getArticleId());
                    startActivity(intent);
                }
                break;

        }
    }


    /**
     * 分享
     */
    private void share() {
        if (mShareUtils == null) {
            mShareUtils = new AppShareUtils(this);
        }
        if (this.mGameContent != null) {
            mShareUtils.showShareDialog(this.mGameContent, TypeConstant.PAGE_GAME_DETAIL);
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {


            if (data != null) {
                UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onBackPressed() {
        if (JCVideoPlayer.backPress()) {
            //判断是否有视频全屏
            return;
        }
        if (ActivityUtils.isActivityExistsInStack(MainActivity.class)) {
            super.onBackPressed();
        } else {
            Intent intent = new Intent(this, MainActivity.class);
            ActivityUtils.finishActivity(this);
            startActivity(intent);
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        //继续播放视频
    }

    @Override
    protected void onPause() {
        super.onPause();
        JCVideoPlayer.releaseAllVideos();
    }

    @Override
    protected void onDestroy() {
        DialogUtils.getInstance().dismissCustomDialog();
        CURRENT_STATE = -1;
        super.onDestroy();
        EventBus.getDefault().unregister(this);

    }


    /**
     * 当横竖屏切换时会调用该方法
     *
     * @author
     */
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            this.mGameContentView.getCwvContentWebview().setFocusable(false);
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            this.mGameContentView.getCwvContentWebview().setFocusable(false);
        }

    }


    @Override
    public void onPositiveClick() {
    }

    @Override
    public void onNegativeClick() {
    }


    private static String URL;
    private static Object[] OBJECTS;
    private static int CURRENT_STATE = -1;

    public static void openDetailActivity(Context context, String articleId, String pageSourceType,
                                          int state, String url, Object... obj) {
        URL = url;
        OBJECTS = obj;
        CURRENT_STATE = state;
        Intent intent = new Intent(context, VideoDetailActivity.class);
        intent.putExtra(Config.Extra.PARAMETER1, articleId);
        intent.putExtra(Config.Extra.PARAMETER2, pageSourceType);
        context.startActivity(intent);
    }
}
